#include <iostream>
#include <fstream>
using namespace std;

#include "polygon.h"
#include "triangulation.h"

int main(int argc, char ** argv)
{
	if(argc!=2){
		cerr<<"Usage: "<<argv[0]<<" *.poly"<<endl;
		return 1;
	}
	
	//open file
	ifstream fin(argv[1]);
	if(fin.good()==false)
	{
		cerr<<"! Error: Cannot open file: "<<argv[1]<<endl;
	}
	
	//create polygon
	c_polygon poly;
	fin>>poly;
	fin.close();
	
	//triangulate the polygon
	vector<triangle> triangles;
	triangulate(poly,triangles);
	
	//output information about the triangles
	cout<<"There are "<<triangles.size()<<" triangles from a polygon with "
	    <<poly.getSize()<<" vertices and "<<poly.size()
	    <<((poly.size()==1)?" boundary":" boundaries")<<endl;
	for(vector<triangle>::iterator i=triangles.begin();i!=triangles.end();i++)
	{
		for(short j=0;j<3;j++) cout<<i->v[j]<<" ";
		cout<<"\n";
	}
	cout<<flush;
	
	return 0;
}
